package com.itheima.smspringboot.controller;


import com.github.pagehelper.PageInfo;
import com.itheima.smspringboot.common.Result;
import com.itheima.smspringboot.entity.SchoolClass;
import com.itheima.smspringboot.entity.SchoolClassString;
import com.itheima.smspringboot.service.SchoolClassService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/schoolclass")
public class SchoolClassController {

    @Resource
    private SchoolClassService schoolClassService;



    @PostMapping("/add")
    public Result add(@RequestBody SchoolClass schoolClass) {
        schoolClassService.add(schoolClass);
        return Result.success();
    }

    //
    @PutMapping("/update")
    public Result update(@RequestBody SchoolClass schoolClass) {

        schoolClassService.updateById(schoolClass);
        return Result.success();
    }


    //
    @DeleteMapping("/delete/{classId}")
    public Result delete(@PathVariable Integer classId) {
        schoolClassService.deleteById(classId);
        return Result.success();

    }
    //
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<SchoolClassString> schoolClassStringList) {
        schoolClassService.deleteBatch(schoolClassStringList);
        return Result.success();

    }



    @GetMapping("/selectAll")
    public Result selectAll(SchoolClassString schoolClassString) {
        List<SchoolClassString> schoolClassStringList = schoolClassService.selectAll(schoolClassString);
        return Result.success(schoolClassStringList);
    }


    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             SchoolClassString schoolClassString) {
        PageInfo pageInfo = schoolClassService.selectPage(pageNum, pageSize,schoolClassString);
        return Result.success(pageInfo);

    }




}
